function [c1, c2, p] = expfitch()
% test exp fit using chebyshev approximation 
%

dx = 0.1;
x=0:dx:50;
if(length(x) < 20)
   disp(sprintf('Too few points for fit: %d', length(x)))
   return
end
noise_amp = 0.1;
noise = noise_amp*(randn(size(x)));
areal = 1;
taureal = 0.5;
aoffset = -50;
y = aoffset + noise + areal*exp(-x/taureal); % test function
clf;
plot(x, y);
hold on;

[a0, a1, tau1] = expfit(x, y);
disp(sprintf('A  = %12.5f    Tau1 = %12.5f  offset = %12.5f\nA  = %12.5f    Tau1 = %12.5f  offset = %12.5f\n', ...   areal, taureal, aoffset, a1, tau1, a0))
areal, taureal, aoffset, a1, tau1, a0))
yfit = a0 + a1*exp(-x/tau1);
plot(x, yfit, 'rx');  % display it for comparison.
hold off;
return;





function [t] = triplet(d, N, j)
t = 0;
if(j < 2 | j > (N-3))
   return;
end

u = ((N + j + 1)/(2*j+3))*d(j+1) -d(j) - ((N-j)/(2*j-1)*d(j-1));
k = 2*d(j)/u;
t = -1/(log(k+1));
return;







